package com.example.demoplus;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;


/**
 * @author wlz
 */
public class AutoCode {
    public static void main(String[] args) {
        //代码生成对象
        AutoGenerator autoGenerator = new AutoGenerator();
        //全局设置对象
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setBaseColumnList(true);
        globalConfig.setBaseResultMap(true);
        //设置作者
        globalConfig.setAuthor("wlz");
        //设置输出路径
        globalConfig.setOutputDir(System.getProperty("user.dir")+ "/src/main/java");
        //设置关闭打开
        globalConfig.setOpen(false);
        //全局设置
        autoGenerator.setGlobalConfig(globalConfig);

        //设置包名
        PackageConfig packageInfo = new PackageConfig();
        packageInfo.setParent(AutoCode.class.getPackage().getName());
        autoGenerator.setPackageInfo(packageInfo);


        //设置数据源
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/weeks?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
        //dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/hgshop?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("root");
        autoGenerator.setDataSource(dataSourceConfig);
        //设置生成策略
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setEntityLombokModel(true);
        strategyConfig.setEntityTableFieldAnnotationEnable(true);
        //驼峰命名
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        //前缀
        //strategyConfig.setTablePrefix("hg_");
        //只生成那个表
        //strategyConfig.setInclude("hg_user","hg_brand");
        strategyConfig.setChainModel(true);

        //@RestController注解
        strategyConfig.setRestControllerStyle(true);


        autoGenerator.setStrategy(strategyConfig);




        //生成代码
        autoGenerator.execute();
    }
}
